﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ui.test.Views;

namespace ui_test.ViewModels;

public partial class UserControl1ViewModel : ViewModelBase
{
    [ObservableProperty] private ObservableCollection<string> _keySets = ["Esc", "F1", "F2"];
    [ObservableProperty] private int _leftClickCount;
    [ObservableProperty] private int _rightClickCount;

    [ObservableProperty] private int _wheelClickCount;

    [ObservableProperty] private DateTimeOffset? _selectedDateTime;

    // [RelayCommand]
    // private void KKK(KeyEventArgs? eventArgs)
    // {
    //     Console.WriteLine(222);
    //     if (eventArgs != null)
    //     {
    //         if (eventArgs.Key == Key.Space)
    //         {
    //             eventArgs.Handled = true;
    //         }
    //     }
    // }

    partial void OnSelectedDateTimeChanged(DateTimeOffset? value)
    {
        if (value.HasValue)
        {
            Console.WriteLine($"Selected date changed to: {value.Value.Date.ToShortDateString()}");
        }
    }

    public UserControl1ViewModel()
    {
        foreach (var key in KeyMapInFirstLine.Keys)
        {
            UserKeySets1.Add(KeyMapInFirstLine[key]);
        }

        foreach (var key in KeyMapInSecLine.Keys)
        {
            UserKeySets2.Add(KeyMapInSecLine[key]);
        }

        foreach (var key in KeyMapIn3thLine.Keys)
        {
            UserKeySets3.Add(KeyMapIn3thLine[key]);
        }

        foreach (var key in KeyMapIn4thLine.Keys)
        {
            UserKeySets4.Add(KeyMapIn4thLine[key]);
        }

        foreach (var key in KeyMapIn5thLine.Keys)
        {
            UserKeySets5.Add(KeyMapIn5thLine[key]);
        }

        foreach (var key in KeyMapIn6thLine.Keys)
        {
            UserKeySets6.Add(KeyMapIn6thLine[key]);
        }
    }

    public Dictionary<string, KeyUserControl> KeyMapInFirstLine = new()
    {
        {
            "Escape", new()
            {
                KeyText = "Esc", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F1", new()
            {
                KeyText = "F1", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F2", new()
            {
                KeyText = "F2", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F3", new()
            {
                KeyText = "F3", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F4", new()
            {
                KeyText = "F4", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F5", new()
            {
                KeyText = "F5", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F6", new()
            {
                KeyText = "F6", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F7", new()
            {
                KeyText = "F7", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F8", new()
            {
                KeyText = "F8", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F9", new()
            {
                KeyText = "F9", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F10", new()
            {
                KeyText = "F10", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F11", new()
            {
                KeyText = "F11", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F12", new()
            {
                KeyText = "F12", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Delete", new()
            {
                KeyText = "Del", CountText = 0, Width = 50, BackgroundColor = Brushes.Black,
                ForegroundColor = Brushes.White
            }
        },
        {
            "PrintScreen", new()
            {
                KeyText = "PrtSc", CountText = 0, Width = 50, BackgroundColor = Brushes.Black,
                ForegroundColor = Brushes.White
            }
        }
    };


    public Dictionary<string, KeyUserControl> KeyMapInSecLine = new()
    {
        {
            "Oem3", new()
            {
                KeyText = "` ~", CountText = 0, Width = 50,
                // BackgroundColor = new SolidColorBrush(),
                BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.Crimson
            }
        },
        {
            "D1", new()
            {
                KeyText = "1 !", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D2", new()
            {
                KeyText = "2 @", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D3", new()
            {
                KeyText = "3 #", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D4", new()
            {
                KeyText = "4 $", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D5", new()
            {
                KeyText = "5 %", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D6", new()
            {
                KeyText = "6 ^", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D7", new()
            {
                KeyText = "7 &", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D8", new()
            {
                KeyText = "8 *", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D9", new()
            {
                KeyText = "9 (", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "0", new()
            {
                KeyText = "0 )", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "OemMinus", new()
            {
                KeyText = "- _", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "OemPlus", new()
            {
                KeyText = "+ =", CountText = 0, Width = 50, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Back", new()
            {
                KeyText = "BackSpace", CountText = 0, Width = 103, BackgroundColor = Brushes.Blue,
                ForegroundColor = Brushes.White
            }
        },
    };

    public Dictionary<string, KeyUserControl> KeyMapIn3thLine = new()
    {
        {
            "Tab", new()
            {
                KeyText = "Tab", CountText = 0, Width = 85, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Q", new()
            {
                KeyText = "Q", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "W", new()
            {
                KeyText = "W", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "E", new()
            {
                KeyText = "E", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "R", new()
            {
                KeyText = "R", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "T", new()
            {
                KeyText = "T", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Y", new()
            {
                KeyText = "Y", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "U", new()
            {
                KeyText = "U", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "I", new()
            {
                KeyText = "I", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "O", new()
            {
                KeyText = "O", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "P", new()
            {
                KeyText = "P", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Oem4", new()
            {
                KeyText = "[ {", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Oem6", new()
            {
                KeyText = "] }", CountText = 0, Width = 50, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Oem5", new()
            {
                KeyText = "| \\", CountText = 0, Width = 70, BackgroundColor = Brushes.Crimson,
                ForegroundColor = Brushes.White
            }
        },
    };

    public Dictionary<string, KeyUserControl> KeyMapIn4thLine = new()
    {
        {
            "CapsLock", new()
            {
                KeyText = "Caps Lock", CountText = 0, Width = 100, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "A", new()
            {
                KeyText = "A", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "S", new()
            {
                KeyText = "S", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "D", new()
            {
                KeyText = "D", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "F", new()
            {
                KeyText = "F", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "G", new()
            {
                KeyText = "G", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "H", new()
            {
                KeyText = "H", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "J", new()
            {
                KeyText = "J", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "K", new()
            {
                KeyText = "K", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "L", new()
            {
                KeyText = "L", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "OemSemicolon", new()
            {
                KeyText = "; :", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Oem7", new()
            {
                KeyText = "' \"", CountText = 0, Width = 50, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Return", new()
            {
                KeyText = "Enter", CountText = 0, Width = 110, BackgroundColor = Brushes.DarkTurquoise,
                ForegroundColor = Brushes.White
            }
        },
    };

    public Dictionary<string, KeyUserControl> KeyMapIn5thLine = new()
    {
        {
            "LeftShift", new()
            {
                KeyText = "Shift", CountText = 0, Width = 125, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Z", new()
            {
                KeyText = "Z", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "X", new()
            {
                KeyText = "X", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "C", new()
            {
                KeyText = "C", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "V", new()
            {
                KeyText = "V", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "B", new()
            {
                KeyText = "B", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "N", new()
            {
                KeyText = "N", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "M", new()
            {
                KeyText = "M", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "OemComma", new()
            {
                KeyText = ", <", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "OemPeriod", new()
            {
                KeyText = ". >", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "OemQuestion", new()
            {
                KeyText = "? /", CountText = 0, Width = 50, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
        {
            "RightShift", new()
            {
                KeyText = "Shift", CountText = 0, Width = 137, BackgroundColor = Brushes.DimGray,
                ForegroundColor = Brushes.White
            }
        },
    };

    public Dictionary<string, KeyUserControl> KeyMapIn6thLine = new()
    {
        {
            "LCtrl", new()
            {
                KeyText = "Ctrl", CountText = 0, Width = 50, BackgroundColor = Brushes.Maroon,
                ForegroundColor = Brushes.White
            }
        },
        {
            "LWin", new()
            {
                KeyText = "Win", CountText = 0, Width = 50, BackgroundColor = Brushes.Maroon,
                ForegroundColor = Brushes.White
            }
        },
        {
            "LeftAlt", new()
            {
                KeyText = "Alt", CountText = 0, Width = 50, BackgroundColor = Brushes.Maroon,
                ForegroundColor = Brushes.White
            }
        },
        {
            "Space", new()
            {
                KeyText = " This is My Favorite Code KeyBoard ", CountText = 0, Width = 525,
                BackgroundColor = Brushes.Maroon, ForegroundColor = Brushes.White
            }
        },
        {
            "RightAlt", new()
            {
                KeyText = "Alt", CountText = 0, Width = 50, BackgroundColor = Brushes.Maroon,
                ForegroundColor = Brushes.White
            }
        },
        {
            "RCtrl", new()
            {
                KeyText = "Ctrl", CountText = 0, Width = 55, BackgroundColor = Brushes.Maroon,
                ForegroundColor = Brushes.White
            }
        },
    };

    public ObservableCollection<KeyUserControl> UserKeySets1 { get; } = [];
    public ObservableCollection<KeyUserControl> UserKeySets2 { get; } = [];
    public ObservableCollection<KeyUserControl> UserKeySets3 { get; } = [];
    public ObservableCollection<KeyUserControl> UserKeySets4 { get; } = [];
    public ObservableCollection<KeyUserControl> UserKeySets5 { get; } = [];
    public ObservableCollection<KeyUserControl> UserKeySets6 { get; } = [];
}